package com.java.app.hacktouch.mouse

import com.java.app.hacktouch.bluetooth.BtConstant
import com.java.app.hacktouch.bluetooth.BtIf

/**
 * Created by guanguojin on 2017/11/16.
 */

object MouseAction {
    private val dataBuffer = ArrayList<Int>()
    private val dataDepth = 2
    private var dataCnt = 0

    fun upOnClick() {
        val mdata = intArrayOf(BtConstant.BE_SOF, MouseParams.lenght, BtConstant.BE_TYPE_MOUSE, 0, 0, 0, 0, 0)
        BtIf.mCommandService?.write(mdata)
    }

    fun leftOnClick() {
        val mdata = intArrayOf(BtConstant.BE_SOF, MouseParams.lenght, BtConstant.BE_TYPE_MOUSE, MouseParams.leftTap, 0, 0, 0, 0)
        BtIf.mCommandService?.write(mdata!!) //click
    }

    fun rightOnClick() {
        val mdata = intArrayOf(BtConstant.BE_SOF, MouseParams.lenght, BtConstant.BE_TYPE_MOUSE, MouseParams.rightTap, 0, 0, 0, 0)
        BtIf.mCommandService?.write(mdata!!) //click
    }

    fun movePointer(lenght: Int, xoffset: Int, yoffset: Int, button: Int) {
        val mdata = intArrayOf(BtConstant.BE_SOF,
                lenght,
                BtConstant.BE_TYPE_MOUSE,
                button,
                xoffset, //x offset
                yoffset, //y offset
                0,
                0)

        dataBuffer.addAll(mdata.toList())
        dataCnt++
        if (dataCnt == dataDepth) {
            dataCnt = 0
            BtIf.mCommandService?.write(IntArray(dataBuffer.size, {i -> dataBuffer.get(i)}))
            dataBuffer.clear()
        }
    }
}
